package com.jwgf.faultnavigation;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.fragment.app.DialogFragment;

public class PictureDialog extends DialogFragment {
    public static String TITLE = "tilte";
    public static String KEY = "picture_id";

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        int id = getArguments().getInt(KEY);
        String title = getArguments().getString(TITLE);

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        ImageView imgView = getView(id);
        imgView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);
        }
        builder.setView(imgView);
        return builder.create();
    }

    private ImageView getView(int resId) {
        ImageView imgView = new ImageView(getActivity());
        imgView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

        imgView.setImageResource(resId);

        return imgView;
    }

}
